package com.itheima.reggie.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.itheima.reggie.common.R;
import com.itheima.reggie.dto.SetmealDto;
import com.itheima.reggie.entity.Setmeal;
import com.itheima.reggie.service.SetmeaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 套餐管理控制器
 */
@RestController
@RequestMapping("/setmeal")
public class SetmealController {

    @Autowired
    private SetmeaService setmeaService;

    @GetMapping("/page")
    public R<IPage<Setmeal>> selectPage( int page, int pageSize, String name){
        IPage<Setmeal> setmealIPage = setmeaService.selectPage(page, pageSize, name);
        return R.success(setmealIPage);
    }

    /**
     * 新增套餐
     */
    @PostMapping()
    public R<Boolean> saveSetmealDto(@RequestBody SetmealDto setmealDto){
       boolean flage =   setmeaService.saveSetmealDto(setmealDto);

        return R.success(flage);
    }

    /**
     * 批量 停售/批量起售
     */
    @PostMapping("/status/{status}")
    public R<Boolean> updateStatus(@PathVariable("status") Integer status , @RequestParam List<Long> ids){

        boolean b = setmeaService.updateStatus(status, ids);
        return R.success(b);
    }
    /**
     * 批量删除
     */
    @DeleteMapping
    public R<Boolean> deletests(@RequestParam List<Long> ids){
       boolean flage =   setmeaService.deletests(ids);
       return R.success(flage);
    }


}
